<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Administrasi extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		$this->load->database();
		$this->load->helper('url');

		$this->load->library('grocery_CRUD');
	}
	public function _example_output($output = null)
	{
		$this->load->view('master/grid',$output);
	}
	public function pengguna_password($id)
	{
		$new_passwd = $this->input->post('passwd');
		$status = 'Gagal';
		if(!empty($id) && !empty($new_passwd) )
		{
			$pengguna = $this->db->where('id',$id)->get('admin')->row();
			if($pengguna)
			{
				$this->db->where('id',$id)->update('admin',array('userpassword'=>md5($new_passwd)));
				$status = 'Berhasil';
			}
		}else{
			$status = 'Password Tidak valid';
		}
		echo $status;
	}
	public function pengguna()
	{
		$this->load->vars('title','Pengguna');

		$crud = new grocery_CRUD();
		
		$crud->set_theme('flexigrid');
		$this->config->load('grocery_crud');
		$crud->set_table('admin');
		$crud->set_subject('Pengguna');
		$crud->unset_fields('userpassword');
		$crud->unset_columns('userpassword');
		$crud->unset_export();
		$crud->unset_print();
		$crud->set_relation('id_cabang','cabang','nama');
		$crud->display_as('id_cabang','Cabang');
		//$output->title = ;
		
		
		$crud->add_action('', '','administrasi/pengguna_password','ui-icon ui-icon-key pengguna_password_cmd');
		$output = $crud->render();
		$this->_example_output($output);
	}
	public function config()
	{
		$this->load->vars('title','Konfigurasi');

		$crud = new grocery_CRUD();
		
		$crud->set_theme('flexigrid');
		$this->config->load('grocery_crud');
		$crud->set_table('config');
		$crud->set_subject('Konfig');
		$crud->unset_add();
		$crud->unset_delete();
		$crud->unset_export();
		$crud->unset_print();
		// $crud->set_relation('id_cabang','cabang','nama');
		// $crud->display_as('id_cabang','Cabang');
		//$output->title = ;
		$crud->unset_texteditor('rekening1');
		$crud->unset_texteditor('rekening2');
		$output = $crud->render();

		$this->_example_output($output);
	}
}